﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for GlobalFunction
/// </summary>
public static class GlobalFunction
{
	public static void ResizeImage(ref int w, ref int h, int fixW)
	{
	    double ratio = (double)w/h;
        if(ratio>1)
        {
            w = fixW;
            double h1 = (double)fixW/ratio;
            h = (int)Math.Round(h1);
        }
        else
        {
            h = fixW;
            double w1 = (double)fixW * ratio;
            w = (int)Math.Round(w1);
        }
	}

    public static void GetImageSize(ref int fileWidth, ref int fileHeight, String filename)
    {
        //lay kich thuoc image, sau do thuc hien resize
        FileStream fs = new FileStream(filename,
        FileMode.Open, FileAccess.Read, FileShare.Read);

        System.Drawing.Image image = System.Drawing.Image.FromStream(fs);
        fileWidth = image.Width;
        fileHeight = image.Height;
    }
    
}
